package org.stephen.recommend.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class BaseController {
	protected <T> T getSessionUser(HttpServletRequest request) {
		return (T) request.getSession().getAttribute("user");
	}

	@Autowired
	protected HttpServletRequest request;
	@Autowired
	protected HttpServletResponse response;
	/**
	 * 使用ModelAttribute设置request的方法在单例controller的情况下会导致线程不安全,
	 * 如果需要使用token取值的方法，建议使用:
	 * UserDetail userDetail = (UserDetail)request.getAttribute("user_claims");
	 * String userId= userDetail.getId();
	 * Role role =  userDetail.getRole();
	 * 方法获取claims,userId和role
	 * HttpServletRequest request使用spring @Autowired 自动注入 是线程安全的。
	 *
	 * edit by stephen.qiu
	 */
}